package org.bigjava.mapper;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.bigjava.bean.Wuye;
import org.bigjava.bean.Xiaoqu;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository("xiaoquMapper")
public interface XiaoquMapper {

    //根据小区名称或小区地址查询小区信息
    @Select("select * from xiaoqu where jsc=1 and name like '%' #{name} '%' and address like '%' #{address} '%'")
    @Results({
            @Result(property ="wuye",column = "wy_id",javaType = Wuye.class,
                    one = @One(select="org.bigjava.mapper.WuyeMapper.wuYeId",fetchType = FetchType.LAZY))
    })
    public List<Xiaoqu> xiaoQuMoHu(String name,String address);
    //根据id修改小区信息
    @Update("update xiaoqu set imgurl=#{imgurl},name=#{name},address=#{address},wy_id=#{wy_id} where id=#{id}")
    public int xiaoQuXiuGai(Xiaoqu xiaoqu);
    //根据id查小区表
    @Select("select * from xiaoqu where id=#{id}")
    @Results({
            @Result(property ="wuye",column = "wy_id",javaType = Wuye.class,
                    one = @One(select="org.bigjava.mapper.WuyeMapper.wuYeId",fetchType = FetchType.LAZY))
    })
    public Xiaoqu xiaoQuId(int id);
    //根据id假删除
    @Update("update xiaoqu set jsc=0 where id=#{id}")
    public int xiaoQuShanChu(int id);
    //小区总数
    @Select("select count(*) from xiaoqu where jsc=1")
    public int xiaoQuZong();
    //小区分页查询
    @Select("select * from xiaoqu where jsc=1 limit #{offset},#{length}")
    @Results({
            @Result(property ="wuye",column = "wy_id",javaType = Wuye.class,
                    one = @One(select="org.bigjava.mapper.WuyeMapper.wuYeId",fetchType = FetchType.LAZY))
    })
    public List<Xiaoqu> xiaoQuFenYe(int offset , int length);
    //添加小区
    @Insert("insert into xiaoqu(imgurl,name,address,wy_id)" +
            " values (#{imgurl},#{name},#{address},#{wy_id})")
    public int xiaoQuAdd(Xiaoqu xiaoqu);

    //查询全部小区
    @Select("select * from xiaoqu where jsc=1")
    public List<Xiaoqu> xiaoQuQuan();


}
